! function() {
    function Event(ele, list) {
        this.meun(ele);
        this.popup();
    }

    Event.prototype.meun = function(ele) {
        var self = this;
        ele.oncontextmenu = function() {
            var ev = ev || window.event;
            self.showList(ev, this);
            return false
        }
    }

    Event.prototype.showList = function(ev, ele) {
        var coord = this.coord(ev);
        var distanc = this.distanc(ele);
        if (distanc.right - coord.x > 130) {
            if (distanc.bottom - coord.y > 120) {
                return this.display(coord.x, coord.y)
            }
            return this.display(coord.x, coord.y - 120)
        } else {
            if (distanc.bottom - coord.y > 120) {
                return this.display(coord.x - 130, coord.y)
            }
            return this.display(coord.x - 130, coord.y - 120)
        }

    }

    Event.prototype.coord = function(ev) {
        if (ev.pageX || ev.pageY) { //firefox、chrome等浏览器
            return {
                x: ev.pageX,
                y: ev.pageY
            };
        }
        return { // IE浏览器
            x: ev.clientX + document.body.scrollLeft - document.body.clientLeft,
            y: ev.clientY + document.body.scrollTop - document.body.clientTop
        };
    }

    Event.prototype.distanc = function(ele) {
        var width = ele.offsetWidth;
        return {
            top: ele.offsetTop,
            left: ele.offsetLeft,
            right: ele.offsetLeft + width,
            bottom: ele.offsetTop + 400
        }
    }

    Event.prototype.display = function(x, y) {
        var list = document.querySelector('.list');
        list.style.cssText += 'display:block;left:' + x + 'px;top:' + y + 'px;'
    }

    Event.prototype.popup = function() {
        document.querySelector(".list").addEventListener('click', function(e) {
            if (e.target.tagName === 'LI') {
                alert(e.target.innerHTML)
            }
        }, false)
    }

    var chunk = document.querySelector(".chunk");

    new Event(chunk)
}()